package com.lee.single.starter.security.util;

import org.springframework.util.DigestUtils;

/**
 * @author Lee
 * @date 2020/8/11
 */
public class SecurityUtils {

    /**
     * 随机生成Token
     */
    public static String buildToken(String prefix, String... strings) {
        long timestamp = System.currentTimeMillis();
        StringBuilder tokenMeta = new StringBuilder();
        for (String s : strings) {
            tokenMeta.append(s);
        }
        tokenMeta.append(timestamp);
        tokenMeta.append(Math.random());

        return prefix + ":" + DigestUtils.md5DigestAsHex(tokenMeta.toString().getBytes());
    }

// todo 用户信息的记录
    /**
     * 获取当前登录用户信息
     */
//    public static UaaDetail current() {
//
//        return (UaaDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//    }
//
//    public static Long id() {
//
//        return current().getId();
//    }

}
